package com.sean.order.service.impl;

import com.sean.order.entity.Order;
import com.sean.order.feign.StockFeignService;
import com.sean.order.mapper.OrderMapper;
import com.sean.order.service.IOrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author Sean
 */
@Service
public class OrderServiceImpl implements IOrderService {
    @Resource
    private OrderMapper orderMapper;

    @Resource
    private StockFeignService stockFeignService;

    @GlobalTransactional
    @Override
    public Order add(Order order) {
        // 插入订单
        orderMapper.insert(order);
        // 扣减库存
        // feign 调用
        stockFeignService.reduce(order.getProductId());
        // 异常
        int i = 1 / 0;
        return order;
    }
}
